home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / rr65 / rrx65.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  36.2 KB  |  1,145 lines

  1. { Delphi Object for R&R XBASE SQL Edition }
  2.  
  3. { Author Chris Brooksbank (cbrooksbank@msn.com) }
  4. { Written : October 1995 }
  5.  
  6. unit RRX65;
  7.  
  8. interface
  9.  
  10. uses
  11.   SysUtils,WinTypes,WinProcs,Messages,Classes,Graphics,Controls,Forms,
  12.   Dialogs,rrxint;
  13.  
  14. type
  15.   TrrFilterUsage = (rrfuSaved,rrfuNone,rrfuComponent,rrfuInteractive);
  16.   TrrDest = (rrdDisplay,rrdTextFile,rrdPrinter,rrdWorksheet,rrdXBase,
  17.              rrdInteractive,rrdCSV,rrdMSWord,rrdRTF);
  18.   TrrExportDest = (rredDisplay,rredFile,rredPrinter);
  19.   TrrwsBorderStyle = (rrwsNone,rrwsFixedSingle,rrwsSizable,rrwsFixedDouble);
  20.  
  21.  
  22.   {XBASE Specific Type definitions}
  23.  
  24.   TRRIndexExt = (rrieNone,rrieCDX,rrieIDX,rrieMDX,rrieNDX,rrieNSX,
  25.                  rrieNTX,rrieWDX);
  26.   TRRScopeUsage = (rrsuSaved,rrsuEntire,rrsuOverride,rrsuInteractive);
  27.   TRRDataType = (rrdtNumeric,rrdtDate,rrdtCharacter);
  28.  
  29.  
  30.   TRRX65 = class(TComponent)
  31.   private
  32.     { Private declarations }
  33.  
  34.      { XBASE Specific Fields Follow }
  35.      fIndexExtension:TRRIndexExt;
  36.      fMasterIndexName:String;
  37.      fMasterIndexTag:String;
  38.      fMasterIndexType:TRRDataType;
  39.      fRelationTables:Tstrings;
  40.      fRelationIndexs:TStrings;
  41.      fRelationTags:Tstrings;
  42.      fRelationAlias:Tstrings;
  43.      fScopeLow:String;
  44.      fScopeHigh:String;
  45.      fScopeUsage:TRRScopeUsage;
  46.      fWriteAllow:Boolean;
  47.      fXbaseEditor:Boolean;
  48.  
  49.  
  50.      { Generic Fields Follow }
  51.      fActive:Boolean;
  52.      fAskPrinter:Boolean;
  53.      fAskReport:Boolean;
  54.      fAuthor:String;
  55.      fAppName:String;
  56.      fBeginPage: Longint;
  57.      fCopies: Longint;
  58.      fDatabasename: String;
  59.      fDataDir    : String;
  60.      fDisplayErrors: Boolean;
  61.      fDisplayStatus: Boolean;
  62.      fEndPage: LongInt;
  63.      fErrorCode: String;
  64.      fErrorMessage: String;
  65.      fExportDest: TrrExportDest;
  66.      fFields: TStrings;
  67.      fFilter: String;
  68.      fFilterUsage: TrrFilterUsage;
  69.      fGroupFields: TStrings;
  70.      fImageDir   : String;
  71.      fLastErrorPage:Longint;
  72.      fLibName: String;
  73.      fMasterTableName: String;
  74.      fMemoName: String;
  75.      fOutputDest: TRRDest;
  76.      fOutputFile: String;
  77.      fPreventEscape: Boolean;
  78.      fPrinterName: String;
  79.      fPrinterPort: String;
  80.      fRepName:String;
  81.      fReportPick: Boolean;
  82.      fSortFields: TStrings;
  83.      fStatusEveryPage: Boolean;
  84.      fSuppressTitle: Boolean;
  85.      fTestPattern: Boolean;
  86.      fUserParamsNames: TStrings;
  87.      fUserParamsValues: TStrings;
  88.      fVersion: String;
  89.      fWait: Boolean;
  90.      fWinBorderStyle: TrrwsBorderStyle;
  91.      fWinControlBox: Boolean;
  92.      fWinHeight: Integer;
  93.      fWinLeft:Integer;
  94.      fWinMaxButton: Boolean;
  95.      fWinMinButton: Boolean;
  96.      fWinParentHandle: Integer;
  97.      fWinTitle: String;
  98.      fWinTop: Integer;
  99.      fWinWidth:Integer;
  100.  
  101.  
  102.      { XBASE Specific private functions follow }
  103.  
  104.      procedure setRelationTables(Value:Tstrings);
  105.      procedure setRelationIndexs(Value:Tstrings);
  106.      procedure setRelationTags(Value:Tstrings);
  107.      procedure setRelationAlias(Value:Tstrings);
  108.      procedure LoadRelations(hReport:Integer);
  109.      procedure LoadScopes(hReport:Integer);
  110.      procedure LoadIndex(hReport:Integer);
  111.      procedure LoadFromReportH(hMyReport:Integer);
  112.  
  113.      { Generic functions follow }
  114.  
  115.      procedure setfActive(Value:Boolean);
  116.      procedure setfAuthor(Value:String);
  117.      procedure LoadFields(hReport:Integer);
  118.      procedure LoadGroupFields(hReport:Integer);
  119.      procedure LoadSortFields(hReport:Integer);
  120.      procedure LoadUserParams(hReport:Integer);
  121.      procedure LoadTitle(hReport:Integer);
  122.      procedure LoadPages(hReport:Integer);
  123.      procedure LoadTable(hReport:Integer);
  124.      procedure LoadFilter(hReport:Integer);
  125.      procedure LoadDests(hReport:Integer);
  126.      procedure LoadPrinter(hReport:Integer);
  127.  
  128.      procedure setfFields(Value:Tstrings);
  129.      procedure setfGroupFields(Value:Tstrings);
  130.      procedure setfSortFields(Value:Tstrings);
  131.      procedure setfUserParamsNames(Value:Tstrings);
  132.      procedure setfUserParamsValues(Value:Tstrings);
  133.      procedure SetLibName(NewLibName:String);
  134.      procedure SetRepName(NewRepName: String);
  135.      procedure SaveToReportH(hReport:Integer);
  136.  
  137.   protected
  138.     { Protected declarations }
  139.   public
  140.     { Public declarations }
  141.     constructor Create(Aowner:TComponent); override;
  142.     destructor Free;
  143.     function execute:Boolean;
  144.     function run:Boolean;
  145.     procedure LoadFromReport;
  146.     function SaveToFile(MyFile:String):Boolean;
  147.     function LoadFromFile(MyFile:String):Boolean;
  148.  
  149.   published
  150.     { Published declarations }
  151.  
  152.     { XBASE Specific Properties Follow }
  153.  
  154.     property IndexExtension:TRRIndexExt read fIndexExtension
  155.                                         write fIndexExtension;
  156.     property MasterIndexType:TRRDataType read  fMasterIndexType
  157.                                          write fMasterIndexType;
  158.     property MasterIndexName:String read fMasterIndexName
  159.                                     write fMasterIndexName;
  160.     property MasterIndexTag:String read fMasterIndexTag
  161.                                    write fMasterIndexTag;
  162.     property ScopeLow:String read fScopeLow write fScopeLow;
  163.     property RelationTables:TStrings read fRelationTables write SetRelationTables;
  164.     property RelationIndexs:TStrings read fRelationIndexs write SetRelationIndexs;
  165.     property RelationTags:Tstrings read fRelationTags write SetRelationTags;
  166.     property RelationAlias:Tstrings read fRelationAlias write setRelationAlias;
  167.     property ScopeHigh:String read fScopeHigh write fScopeHigh;
  168.     property ScopeUsage:TRRScopeUsage read fScopeUsage write fScopeUsage;
  169.     property WriteAllow:Boolean read fWriteAllow write fWriteAllow;
  170.     property XbaseEditor:Boolean read fXbaseEditor write fXbaseEditor;
  171.  
  172.     { Generic Properties follow }
  173.  
  174.     property Active: Boolean read fActive write SetfActive;
  175.     property AppName: String read fAppName write fAppName;
  176.     property AskPrinter:Boolean read fAskPrinter write fAskPrinter;
  177.     property AskReport:Boolean read fAskReport write fAskReport;
  178.     property Author: String read fAuthor write setfAuthor;
  179.     property BeginPage: Longint read fBeginPage write fBeginPage;
  180.     property Copies: Longint read fCopies write fCopies;
  181.     property Databasename:String read fDatabasename write fDatabasename;
  182.     property DataDirectory:String read fDataDir write fDataDir;
  183.     property DisplayErrors: Boolean read fDisplayErrors write fDisplayErrors;
  184.     property DisplayStatus: Boolean read fDisplayStatus write fDisplayStatus;
  185.     property EndPage: Longint read fEndPage write fEndPage;
  186.     property ErrorCode: String read fErrorcode write fErrorcode;
  187.     property ErrorMessage: String read fErrorMessage write fErrorMessage;
  188.     property ExportDest: TrrExportDest read fExportDest write fExportDest;
  189.     property Fields: TStrings read fFields write setfFields;
  190.     property Filter: String read fFilter write fFilter;
  191.     property FilterUsage: TrrFilterUsage read fFilterUsage write fFilterUsage;
  192.     property GroupFields: TStrings read fGroupFields write setfGroupFields;
  193.     property ImageDir: String read fImageDir write fImageDir;
  194.     property LastErrorPage: Longint read fLastErrorPage write fLastErrorPage;
  195.     property MasterTableName: String read fMasterTableName write fMasterTableName;
  196.     property MemoName: String read fMemoName write fMemoName;
  197.     property OutputDest: TrrDest read fOutputDest write fOutputDest;
  198.     property OutputFile: String read fOutputFile write fOutputFile;
  199.     property PreventEscape: Boolean read fPreventEscape write fPreventEscape;
  200.     property PrinterName: String read fPrinterName write fPrinterName;
  201.     property PrinterPort: String read fPrinterPort write fPrinterPort;
  202.     property ReportLibrary:String read fLibName write setLibName;
  203.     property ReportName: String read fRepName write setRepName;
  204.     property SortFields: TStrings read fSortFields write setfSortFields;
  205.     property StatusEveryPage: Boolean read fStatusEveryPage
  206.                                       write fStatusEveryPage;
  207.     property SuppressTitle: Boolean read fSuppressTitle write fSuppressTitle;
  208.     property TestPattern: Boolean read fTestPattern write fTestPattern;
  209.     property UserParamsNames: TStrings read fUserParamsNames
  210.                                        write setfUserParamsNames;
  211.     property UserParamsValues: TStrings read fUserParamsValues
  212.                                        write setfUserParamsValues;
  213.     property Version:String read fVersion write fversion;
  214.     property Wait: Boolean read fWait write fWait;
  215.     property WinBorderStyle:TrrwsBorderStyle read fWinBorderStyle
  216.              write fWinBorderStyle;
  217.     property WinControlBox: Boolean read fWinControlBox write fWinControlBox;
  218.     property WinHeight: Integer read fWinHeight write fWinHeight;
  219.     property WinLeft: Integer read fWinLeft write fWinLeft;
  220.     property WinMaxButton: Boolean read fWinMaxButton write fWinMaxButton;
  221.     property WinMinButton: Boolean read fWinMinButton write fWinMinButton;
  222.     property WinParentHandle: Integer read fWinParentHandle write fWinParentHandle;
  223.     property WinTitle: String read fWinTitle write fWinTitle;
  224.     property WinTop:Integer read fWinTop write fWinTop;
  225.     property WinWidth:Integer read fWinWidth write fWinWidth;
  226.  
  227. end;
  228.  
  229. procedure Register;
  230.  
  231. implementation
  232.  
  233. { ************************************************************************** }
  234. constructor TRRX65.create(AOwner:Tcomponent);
  235. { ************************************************************************** }
  236. begin
  237.   inherited create(AOwner);
  238.  
  239.   initruntimeinstance;
  240.  
  241.   { XBASE Specific TSTRING fields }
  242.   fRelationTables:=TStringList.Create;
  243.   fRelationIndexs:=TStringList.Create;
  244.   fRelationTags:=TStringList.Create;
  245.   fRelationAlias:=TStringList.Create;
  246.   fXbaseEditor:=true;
  247.  
  248.   { Generic TSTRING fields }
  249.   fFields:=TStringList.Create;
  250.   fGroupFields:=TStringList.Create;
  251.   fSortFields:=TstringList.Create;
  252.   fUserParamsNames:=TStringList.Create;
  253.   fUserParamsValues:=TStringList.Create;
  254.  
  255.   fWait:=true;
  256.   fMasterIndexType:=rrdtCharacter;
  257.   fIndexExtension:=rrieNTX;
  258.   fAppName:=Application.exename;
  259.   fAuthor:='cbrooksbank@msn.com';
  260.   fAskPrinter:=true;
  261.  
  262.  
  263. end;
  264.  
  265. { ************************************************************************** }
  266. destructor TRRX65.Free;
  267. { ************************************************************************** }
  268. begin
  269.  
  270.   { XBASE Specific TSTRING fields }
  271.   fRelationTables.Free;
  272.   fRelationIndexs.Free;
  273.   fRelationTags.Free;
  274.   fRelationAlias.Free;
  275.  
  276.   { Generic TSTRING Fields }
  277.   fFields.free;
  278.   fGroupFields.free;
  279.   fSortFields.free;
  280.   fUserParamsNames.free;
  281.   fUserParamsValues.free;
  282.  
  283.   endruntimeinstance;
  284.  
  285.   inherited Free;
  286. end;
  287.  
  288.  
  289. { ************************************************************************** }
  290. procedure Register;
  291. { ************************************************************************** }
  292. begin
  293.   RegisterComponents('Data Access', [TRRX65]);
  294. end;
  295.  
  296. { ************************************************************************** }
  297. procedure TRRX65.LoadFromReport;
  298. { ************************************************************************** }
  299. { Using the fRepname and fLibname load object info from report defaults }
  300. var
  301.   hMyReport:Integer;
  302.   MyApp_,MyLib_,MyRep_:PChar;
  303. begin
  304.   if ((flibname<>'') and (frepname<>'')) then
  305.   begin
  306.     MyApp_:=StrAlloc(length(fAppName)+1);
  307.     StrPCopy(MyApp_,fAppName);
  308.     MyLib_:=StrAlloc(length(fLibName)+1);
  309.     StrPCopy(MyLib_,fLibName);
  310.     MyRep_:=StrAlloc(length(fRepName)+1);
  311.     StrPCopy(MyRep_,fRepName);
  312.     try
  313.  
  314.       hMyReport:=ChooseReport(MyApp_,MyLib_,MyRep_,StrBufSize(MyRep_));
  315.       if hMyReport>0 then
  316.       begin
  317.         try
  318.           LoadFromReportH(hMyReport);
  319.         finally
  320.           EndReport(hMyReport);
  321.         end;
  322.       end;
  323.  
  324.       if hMyReport<1 then MessageDlg('Cant load info on R&&R report '+ReportName,
  325.                                      mtError,[mbAbort],0);
  326.     finally
  327.       StrDispose(MyApp_);
  328.       StrDispose(MyLib_);
  329.       StrDIspose(MyRep_);
  330.     end;
  331.   end;
  332. end;
  333.  
  334.  
  335. { ************************************************************************** }
  336. procedure TRRX65.LoadFromReportH(hMyReport:Integer);
  337. { ************************************************************************** }
  338.  
  339. { Using passed report handle load object info from report defaults }
  340.  
  341. begin
  342.  
  343.   { Clear XBASE Specific TSTRING Fields }
  344.   fRelationTables.Clear;
  345.   fRelationIndexs.Clear;
  346.   fRelationTags.Clear;
  347.   fRelationAlias.Clear;
  348.  
  349.   { Clear Generic TSTRING Fields }
  350.   fFields.Clear;
  351.   fGroupFields.Clear;
  352.   fSortFields.Clear;
  353.   fUserParamsNames.Clear;
  354.   fUserParamsValues.Clear;
  355.  
  356.   { Load XBASE Specific Properties }
  357.   LoadRelations(hMyReport);
  358.   LoadScopes(hMyReport);
  359.   LoadIndex(hMyReport);
  360.  
  361.   { Load Generic Properties }
  362.   LoadFields(hMyReport);
  363.   LoadGroupFields(hMyReport);
  364.   LoadSortFields(hMyReport);
  365.   LoadUserParams(hMyReport);
  366.   LoadTitle(hMyReport);
  367.   LoadPages(hMyReport);
  368.   LoadTable(hMyReport);
  369.   LoadFilter(hMyReport);
  370.   LoadDests(hMyReport);
  371.   LoadPrinter(hMyReport);
  372.  
  373. end;
  374.  
  375. { ************************************************************************** }
  376. procedure TRRX65.setlibname(NewLibName:String);
  377. { ************************************************************************** }
  378. var
  379.   Designing:Boolean;
  380. begin
  381.   flibname:=NewLibName;
  382.   Designing:=(csDesigning in ComponentState);
  383.   if ((csReading in ComponentState) or (csLoading in ComponentState)) then
  384.     Designing:=false;
  385.  
  386.   if (Designing and (fLibName<>'') and (fRepName<>'') ) then
  387.   begin
  388.     if MessageDlg('Load Properties From Report ?',mtconfirmation,
  389.                   [mbNo,mbYes],0)=mrYes then loadfromreport;
  390.   end;
  391. end;
  392.  
  393. { ************************************************************************** }
  394. function TRRX65.Run:Boolean;
  395. { ************************************************************************** }
  396. begin
  397.   Result:=Execute;
  398. end;
  399.  
  400.  
  401. { ************************************************************************** }
  402. function TRRX65.Execute:Boolean;
  403. { ************************************************************************** }
  404. var
  405.   { Handle of report }
  406.   hReport: Integer;
  407.  
  408.   { Flags returned after report was run }
  409.   ECode:Integer;
  410.   cmdshow: Integer;
  411.   PageCount:LongInt;
  412.   EMsg:Pchar;
  413.   ErrorMess: String;
  414.  
  415.   AppName_,LibName_,RepName_:Pchar;
  416. begin
  417.   {Run the report }
  418.   Result:=false;
  419.  
  420.   { Convert Pascal type strings to C++ strings as expected by DLL }
  421.   AppName_:=StrAlloc(length(fAppName)+1);
  422.   LibName_:=StrAlloc(length(fLibName)+1);
  423.   RepName_:=StrAlloc(length(fRepName)+1);
  424.   StrPCopy(AppName_,fAppName);
  425.   StrPCopy(LibName_,flibname);
  426.   EMsg:=StrAlloc(256);
  427.   if faskreport then StrPCopy(RepName_,'') else
  428.     StrPCopy(RepName_,fRepName);
  429.  
  430.   try
  431.     { If object specifys ask for report then blank out the report name }
  432.     { to make sure user is prompted for report name }
  433.  
  434.     hReport:=ChooseReport(Appname_,LibName_,RepName_,StrBufSize(RepName_));
  435.  
  436.     if hReport>0 then begin
  437.       try
  438.         { Pass all the propertys to RSREPORT.DLL }
  439.         SaveToReportH(hReport);
  440.  
  441.         { Run the report and then clean up }
  442.         cmdshow:=SW_SHOWNORMAL;
  443.         fErrorCode:='';
  444.         fErrorMessage:='';
  445.         ResetErrorInfo;
  446.         if ExecRunTime(hReport,fWait,cmdshow,@ECode,@PageCount,EMsg,StrBufSize(EMsg))
  447.         then Result:=True else begin
  448.           geterrorinfo(Emsg,StrBufSize(EMsg),@Ecode);
  449.           fErrorMessage:=StrPas(EMsg);
  450.  
  451.           case Ecode of
  452.             Ord('C'):fErrorCode:='Cancelled';
  453.             Ord('D'):fErrorCode:='Diagnostic';
  454.             Ord('I'):fErrorCode:='Iteration';
  455.             Ord('J'):fErrorCode:='Job Control';
  456.             Ord('L'):fErrorCode:='Library';
  457.             Ord('S'):fErrorCode:='Syntax';
  458.             Ord('V'):fErrorCode:='Value';
  459.           else
  460.             fErrorCode:=Chr(Ecode);
  461.           end;
  462.  
  463.           MessageDlg('R&&R Error : '+StrPas(EMsg),mtError,[mbAbort],0);
  464.         end;
  465.       finally
  466.         EndReport(hReport);
  467.       end;
  468.     end;
  469.     fLastErrorPage:=PageCount;
  470.     if hReport<1 then MessageDlg('Cant allocate handle for report '+fRepname,
  471.                                  mtError,[mbAbort],0)
  472.   finally
  473.     StrDispose(AppName_);
  474.     StrDispose(LibName_);
  475.     StrDispose(RepName_);
  476.     StrDispose(EMsg);
  477.   end;
  478. end;
  479.  
  480. { ************************************************************************** }
  481. procedure TRRX65.LoadUserParams(hReport:Integer);
  482. { ************************************************************************** }
  483. var
  484.   ParamName,ParamValue:Pchar;
  485. begin
  486.   ParamName:=StrAlloc(31);
  487.   ParamValue:=StrAlloc(31);
  488.   try
  489.     if GetFirstUserParam(hReport,ParamName,StrBufSize(ParamName),
  490.                       paramValue,StrBufSize(ParamValue)) then begin
  491.       fUserParamsNames.Add(StrPas(ParamName));
  492.       fUserParamsValues.Add(StrPas(ParamValue));
  493.     end;
  494.     while GetNextUserParam(hReport,ParamName,StrBufSize(ParamName),
  495.                            ParamValue,StrBufSize(ParamValue)) do begin
  496.       fUserParamsNames.Add(StrPas(ParamName));
  497.       fUSerParamsValues.Add(StrPas(ParamValue));
  498.     end;
  499.   finally
  500.     StrDispose(ParamName);
  501.     StrDispose(ParamValue);
  502.   end;
  503. end;
  504.  
  505. { ************************************************************************** }
  506. procedure TRRX65.LoadFields(hReport:Integer);
  507. { ************************************************************************** }
  508. var
  509.   FieldName:PChar;
  510. begin
  511.   FieldName:=StrAlloc(31);
  512.   try
  513.     if GetFirstFieldName(hReport,FieldName,StrBufSize(FieldName)) then
  514.       fFields.Add(StrPas(FieldName));
  515.     while GetNextFieldName(hReport,FieldName,StrBufSize(FieldName)) do
  516.       fFields.Add(StrPas(FieldName));
  517.   finally
  518.     StrDispose(FieldName);
  519.   end;
  520. end;
  521.  
  522. { ************************************************************************** }
  523. procedure TRRX65.LoadGroupFields(hReport:Integer);
  524. { ************************************************************************** }
  525. var
  526.   GroupField:Pchar;
  527. begin
  528.   GroupField:=StrAlloc(31);
  529.   try
  530.     if GetFirstGroupField(hReport,GroupField,StrBufSize(GroupField)) then
  531.       fGroupFields.Add(StrPas(GroupField));
  532.     while GetNextGroupField(hReport,GroupField,StrBufSize(GroupField)) do
  533.       fGroupFields.Add(StrPas(GroupField));
  534.   finally
  535.     StrDispose(GroupField);
  536.   end;
  537. end;
  538.  
  539. { ************************************************************************** }
  540. procedure TRRX65.LoadSortFields(hReport:Integer);
  541. { ************************************************************************** }
  542. var
  543.   SortField:Pchar;
  544. begin
  545.   SortField:=StrAlloc(31);
  546.   try
  547.     if GetFirstSortField(hReport,SortField,StrBufSize(SortField)) then
  548.       fSortFields.Add(StrPas(SortField));
  549.     while GetNextSortField(hReport,SortField,StrBufSize(SortField)) do
  550.       fSortFields.Add(StrPas(SortField));
  551.   finally
  552.     StrDispose(SortField);
  553.   end;
  554. end;
  555.  
  556. { ************************************************************************** }
  557. procedure TRRX65.SetRepName(NewRepName: String);
  558. { ************************************************************************** }
  559. var
  560.   Designing:Boolean;
  561. begin
  562.   fRepName:=NewRepName;
  563.   Designing:=(csDesigning in ComponentState);
  564.   if ((csReading in ComponentState) or (csLoading in ComponentState)) then
  565.     Designing:=false;
  566.  
  567.   if (Designing and (fLibName<>'') and (fRepName<>'') ) then
  568.   begin
  569.     if MessageDlg('Load Properties From Report ?',mtconfirmation,
  570.                   [mbYes,mbNo],0)=mrYes then loadfromreport;
  571.   end;
  572. end;
  573.  
  574. { ************************************************************************** }
  575. procedure TRRX65.SetfFields(Value:Tstrings);
  576. { ************************************************************************** }
  577. begin
  578.   fFields.Assign(Value);
  579. end;
  580.  
  581. { ************************************************************************** }
  582. procedure TRRX65.SetfGroupFields(Value:Tstrings);
  583. { ************************************************************************** }
  584. begin
  585.   fGroupFields.Assign(Value);
  586. end;
  587.  
  588. { ************************************************************************** }
  589. procedure TRRX65.SetfSortFields(Value:Tstrings);
  590. { ************************************************************************** }
  591. begin
  592.   fSortFields.Assign(Value);
  593. end;
  594.  
  595. { ************************************************************************** }
  596. procedure TRRX65.SetfUserParamsNames(Value:Tstrings);
  597. { ************************************************************************** }
  598. begin
  599.   fUserParamsNames.Assign(Value);
  600. end;
  601.  
  602. { ************************************************************************** }
  603. procedure TRRX65.SetfUserParamsValues(Value:Tstrings);
  604. { ************************************************************************** }
  605. begin
  606.   fUserParamsValues.Assign(Value);
  607. end;
  608.  
  609. { ************************************************************************** }
  610. procedure TRRX65.SetfActive(Value:Boolean);
  611. { ************************************************************************** }
  612. begin
  613.   if (csDesigning in ComponentState) and (Value=True) then execute;
  614. end;
  615.  
  616. { ************************************************************************** }
  617. procedure TRRX65.SetfAuthor(Value:String);
  618. { ************************************************************************** }
  619. begin
  620.   if Value<>'cbrooksbank@msn.com' then
  621.   messagedlg('Please send bugs/comments/enhancements to cbrooksbank@msn.com',mtInformation,
  622.               [mbOk],0);
  623.   fAuthor:='cbrooksbank@msn.com';
  624. end;
  625.  
  626. { ************************************************************************** }
  627. procedure TRRX65.LoadTitle(hReport:Integer);
  628. { ************************************************************************** }
  629. var
  630.   title_:PChar;
  631. begin
  632.   title_:=StrAlloc(256);
  633.   try
  634.     if GetWinTitle(hReport,title_,StrBufSize(title_)) then
  635.       fWinTitle:=StrPas(title_);
  636.   finally
  637.     StrDispose(title_);
  638.   end;
  639. end;
  640.  
  641. { ************************************************************************** }
  642. procedure TRRX65.LoadPages(hReport:Integer);
  643. { ************************************************************************** }
  644. begin
  645.   GetBeginPage(hReport,@fBeginPage);
  646.   GetEndPage(hReport,@fEndPage);
  647.   GetCopies(hReport,@fCopies);
  648. end;
  649.  
  650. { ************************************************************************** }
  651. procedure TRRX65.LoadTable(hReport:Integer);
  652. { ************************************************************************** }
  653. var
  654.   table_:Pchar;
  655. begin
  656.   table_:=StrAlloc(256);
  657.   try
  658.     if GetMasterTableName(hReport,table_,StrBufSize(table_)) then
  659.       fMasterTableName:=StrPas(table_);
  660.   finally
  661.     StrDispose(table_);
  662.   end;
  663. end;
  664.  
  665.  
  666. { ************************************************************************** }
  667. procedure TRRX65.LoadFilter(hReport:Integer);
  668. { ************************************************************************** }
  669. var
  670.   filter_:Pchar;
  671. begin
  672.   filter_:=StrAlloc(256);
  673.   try
  674.     if getFilter(hReport,filter_,StrBufSize(filter_)) then
  675.       fFilter:=StrPas(filter_);
  676.   finally
  677.     StrDispose(Filter_);
  678.   end;
  679. end;
  680.  
  681. { ************************************************************************** }
  682. procedure TRRX65.LoadDests(hReport:Integer);
  683. { ************************************************************************** }
  684. var
  685.   Dest_:Pchar;
  686.   DestStr:String;
  687. begin
  688.  
  689. Dest_:=StrAlloc(256);
  690. try
  691.  
  692.   { Load fExportDest}
  693.   if getExportDest(hReport,Dest_) then
  694.   begin
  695.     DestStr:=StrPas(Dest_);
  696.     if DestStr[1]='D' then
  697.       fExportDest:=rredDisplay;
  698.     if DestStr[1]='F' then
  699.       fExportDest:=rredFile;
  700.     if DestStr[1]='P' then
  701.       fExportDest:=rredPrinter;
  702.   end;
  703.  
  704.   { Load fOutPutDest }
  705.   if getOutputDest(hReport,Dest_) then
  706.   begin
  707.     DestStr:=StrPas(Dest_);
  708.     if DestStr[1]='D' then
  709.       fOutPutDest:=rrdDisplay;
  710.     if DestStr[1]='A' then
  711.       fOutPutDest:=rrdTextFile;
  712.     if DestStr[1]='T' then
  713.       fOutPutDest:=rrdTextFile;
  714.     if DestStr[1]='P' then
  715.       fOutPutDest:=rrdPrinter;
  716.     if DestStr[1]='W' then
  717.       fOutPutDest:=rrdWorksheet;
  718.     if DestStr[1]='X' then
  719.       fOutPutDest:=rrdXBase;
  720.     if DestStr[1]='?' then
  721.       fOutPutDest:=rrdInteractive;
  722.   end;
  723.  
  724.   { Load fOutputFile }
  725.   if getOutputDest(hReport,Dest_) then
  726.     fOutPutFile:=StrPas(Dest_);
  727. finally
  728.   StrDispose(Dest_);
  729. end;
  730.  
  731. end;
  732.  
  733. { ************************************************************************** }
  734. procedure TRRX65.LoadPrinter(hReport:Integer);
  735. { ************************************************************************** }
  736. var
  737.   Printer_,Port_:Pchar;
  738. begin
  739.   Printer_:=StrAlloc(256);
  740.   Port_:=StrAlloc(256);
  741.   try
  742.     if getPrinter(hReport,Printer_,StrBufSize(Printer_)) then
  743.       fPrinterName:=StrPas(Printer_);
  744.     if getPrinterPort(hReport,Port_,StrBufSize(Port_)) then
  745.       fPrinterPort:=StrPas(Port_);
  746.   finally
  747.     StrDispose(Printer_);
  748.     StrDispose(Port_);
  749.   end;
  750. end;
  751.  
  752. { ************************************************************************** }
  753. procedure TRRX65.SaveToReportH(hReport:Integer);
  754. { ************************************************************************** }
  755.  
  756. { Given a report handle save object properties to the report }
  757. { Pass all the propertys to RSREPORT.DLL }
  758.  
  759. var
  760.   { Temp vars to hold Pchar versions of String properties }
  761.   PrinterName_:PChar;
  762.   PrinterPort_:PChar;
  763.   filter_:PChar;
  764.   MasterTableName_,MemoName_,OutputFile_,WinTitle_:PChar;
  765.   Tablename_,Databasename_:PChar;
  766.  
  767.   CharString:String;
  768.   SiField,SiField2:PChar;
  769.   datadir_,imagedir_:PChar;
  770.  
  771.   i,maxi:Integer;
  772.  
  773.   { XBASE specific VARS }
  774.   lowscope_,highscope_:PChar;
  775.   MasterIndex_,MasterTag_:PChar;
  776.   RelationTable_,RelationIndex_,RelationTag_,RelationAlias_:PChar;
  777.  
  778.  
  779. begin
  780.  
  781.   PrinterName_:= StrAlloc(256);
  782.   PrinterPort_:= StrAlloc(31);
  783.   filter_:= StrAlloc(256);
  784.   MasterTableName_:=StrAlloc(256);
  785.   MemoName_:=StrAlloc(256);
  786.   OutputFile_:=StrAlloc(256);
  787.   WinTitle_:=StrAlloc(256);
  788.   Tablename_:=StrAlloc(256);
  789.   DatabaseName_:=StrAlloc(256);
  790.   SiField:=StrAlloc(256);
  791.   SiField2:=StrAlloc(256);
  792.   datadir_:=StrAlloc(256);
  793.   imagedir_:=StrAlloc(256);
  794.   lowscope_:=StrAlloc(256);
  795.   highscope_:=StrAlloc(256);
  796.   MasterIndex_:=StrAlloc(256);
  797.   MasterTag_:=StrAlloc(256);
  798.   RelationTable_:=StrAlloc(256);
  799.   RelationIndex_:=StrAlloc(256);
  800.   RelationTag_:=StrAlloc(256);
  801.   RelationAlias_:=StrAlloc(256);
  802.   try
  803.  
  804.  
  805.     if AskPrinter then fPrinterName:='?';
  806.  
  807.     { Convert Pascal type strings to C++ strings as expected by DLL }
  808.     StrPCopy(Filter_,fFilter);
  809.     StrPCopy(MasterTableName_,fMasterTableName);
  810.     StrPCopy(MemoName_,fMemoName);
  811.     StrPCopy(OutputFile_,fOutputFile);
  812.     StrPCopy(Printername_,fPrinterName);
  813.     StrPCopy(PrinterPort_,fPrinterPort);
  814.     StrPCopy(WinTitle_,fWinTitle);
  815.     StrPCopy(Databasename_,fDatabasename);
  816.     StrPCopy(ImageDir_,fimagedir);
  817.     StrPCopy(DataDir_,fdatadir);
  818.  
  819.     { XBASE Specific StrPcopys }
  820.     StrPcopy(lowscope_,fscopelow);
  821.     StrPCopy(highscope_,fscopehigh);
  822.     StrPCopy(Masterindex_,fMasterIndexName);
  823.     StrPCopy(Mastertag_,fMasterIndexTag);
  824.  
  825.     SetBeginPage(hReport,fBeginPage);
  826.     SetCopies(hReport,fCopies);
  827.     SetDisplayErrors(hReport,fDisplayErrors);
  828.     SetDisplayStatus(hReport,FDisplayStatus);
  829.     SetEndPage(hReport,fEndPage);
  830.  
  831.     CharString:=Copy('DFP',Ord(fExportDest)+1,1);
  832.     SetExportDest(hReport,CharString[1]);
  833.  
  834.     SetFilter(hReport,Filter_);
  835.  
  836.     CharString:=Copy('SEO?',Ord(fFilterUsage)+1,1);
  837.     SetFilterUsage(hReport,CharString[1]);
  838.  
  839.     if fMasterTableName<>''then
  840.       SetMasterTableName(hReport,MasterTableName_);
  841.  
  842.     if fMemoName<>'' then
  843.       SetMemoName(hReport,MemoName_);
  844.  
  845.     CharString:=Copy('DAPWX?CMR',Ord(fOutputDest)+1,1);
  846.     SetOutputDest(hReport,CharString[1]);
  847.  
  848.     SetOutPutFile(hReport,OutputFile_);
  849.     SetPreventEscape(hReport,fPreventEscape);
  850.     SetStatusEveryPage(hReport,fStatusEveryPage);
  851.     SetTestPattern(hReport,fTestPattern);
  852.  
  853.     CharString:=Copy('0123',Ord(fWinBorderStyle)+1,1);
  854.     SetWinBorderStyle(hReport,Ord(CharString[1])-Ord('0'));
  855.  
  856.     SetWinControlBox(hReport,fWinControlBox);
  857.     SetWinHeight(hReport,fWinHeight);
  858.     SetWinLeft(hReport,fWinLeft);
  859.     SetWinMaxButton(hReport,fWinMaxButton);
  860.     SetWinMinButton(hReport,fWinMinButton);
  861.     SetWinParentHandle(hReport,fWinParentHandle);
  862.     SetWinTitle(hReport,WinTitle_);
  863.     SetWinTop(hReport,fWinTop);
  864.     SetWinWidth(hReport,fWinWidth);
  865.  
  866.     { Set sort fields }
  867.     for i:=0 to (fSortFields.Count-1) do begin
  868.       if ((fSortFields[i]<>'') and
  869.          (Pos('RECNO',UpperCase(fSortFields[i]))=0)) then begin
  870.         StrPCopy(SiField,fSortFields[i]);
  871.         SetSortField(hReport,SiField,i+1);
  872.       end;
  873.     end;
  874.  
  875.     { Set Group Fields }
  876.     for i:=0 to (fGroupFields.Count-1) do begin
  877.       if fGroupFields[i]<>'' then begin
  878.         StrPCopy(SiField,fGroupFields[i]);
  879.         SetGroupField(hReport,SiField,i+1);
  880.       end;
  881.     end;
  882.  
  883.     { Set user paramaters }
  884.     for i:=0 to (fUserParamsNames.Count-1) do begin
  885.       if fUserParamsNames[i]<>'' then begin
  886.         StrPCopy(SiField,fUserParamsNames[i]);
  887.         StrPCopy(SiField2,fUserParamsValues[i]);
  888.         SetUserParam(hreport,SiField,SiField2);
  889.       end;
  890.     end;
  891.  
  892.  
  893.     if ((fPrinterName<>'') or AskPrinter) then
  894.     begin
  895.       SetPrinter(hReport,PrinterName_);
  896.       SetPrinterPort(hReport,PrinterPort_);
  897.     end;
  898.  
  899.     if fimagedir<>'' then SetImageDir(hreport,imagedir_);
  900.     if fdatadir<>'' then SetDataDir(hreport,datadir_);
  901.  
  902.     { Set XBASE specific things }
  903.  
  904.     SetXBaseEditor(hReport,fXbaseEditor);
  905.     SetWriteAllow(hReport,fWriteAllow);
  906.     SetIndexExtension(hReport,Ord(fIndexExtension));
  907.  
  908.     CharString:=Copy('SEO?',Ord(fScopeUsage)+1,1);
  909.     SetScopeUsage(hReport,CharString[1]);
  910.  
  911.     if fScopeLow<>'' then SetLowScope(hreport,LowScope_);
  912.     if fScopeHigh<>'' then SetHighScope(hreport,HighScope_);
  913.  
  914.     if fMasterIndexName<>'' then begin
  915.       CharString:=Copy('NDC',Ord(fMasterIndexType)+1,1);
  916.       SetMasterIndexInfo(hReport,MasterIndex_,CharString[1],MasterTag_);
  917.     end;
  918.  
  919.     { Set XBASE Relationships }
  920.     for i:=0 to (fRelationTables.Count-1) do begin
  921.       StrPCopy(RelationTable_,fRelationTables[i]);
  922.       StrPCopy(RelationIndex_,fRelationIndexs[i]);
  923.       StrPCopy(RelationTag_,fRelationTags[i]);
  924.       StrPCopy(RelationAlias_,fRelationAlias[i]);
  925.       SetRelationInfo(hReport,RelationTable_,RelationIndex_,RelationTag_,
  926.                       RelationAlias_,i+1);
  927.     end;
  928.   finally
  929.     StrDispose(PrinterName_);
  930.     StrDispose(PrinterPort_);
  931.     StrDispose(filter_);
  932.     StrDispose(MasterTableName_);
  933.     StrDispose(MemoName_);
  934.     StrDispose(OutputFile_);
  935.     StrDispose(WinTitle_);
  936.     StrDispose(Tablename_);
  937.     StrDispose(DatabaseName_);
  938.     StrDispose(SiField);
  939.     StrDispose(SiField2);
  940.     StrDispose(datadir_);
  941.     StrDispose(imagedir_);
  942.     StrDispose(lowscope_);
  943.     StrDispose(highscope_);
  944.     StrDispose(MasterIndex_);
  945.     StrDispose(MasterTag_);
  946.     StrDispose(RelationTable_);
  947.     StrDispose(RelationIndex_);
  948.     StrDispose(RelationTag_);
  949.     StrDispose(RelationAlias_);
  950.   end;
  951.  
  952. end;
  953.  
  954.  
  955. { ************************************************************************** }
  956. function TRRX65.SaveToFile(MyFile:String):Boolean;
  957. { ************************************************************************** }
  958. var
  959.   hReport:Integer;
  960.   MyFile_,MyApp_,MyLib_,MyRep_:PChar;
  961. begin
  962.   MyFile_:=StrAlloc(256);
  963.   MyApp_:=StrAlloc(256);
  964.   MyLib_:=StrAlloc(256);
  965.   MyRep_:=StrAlloc(256);
  966.   try
  967.  
  968.     Result:=false;
  969.     StrPCopy(MyApp_,fAppName);
  970.     StrPCopy(MyLib_,fLibName);
  971.     StrPCopy(MyRep_,fRepName);
  972.  
  973.     hReport:=ChooseReport(MyApp_,MyLib_,MyRep_,StrBufSize(MyRep_));
  974.     try
  975.       if hReport>0 then
  976.       begin
  977.         StrPCopy(MyFile_,MyFile);
  978.         savetoreportH(hReport);
  979.         if writeRunTimeRecord(hReport,MyFile_) then result:=true;
  980.       end;
  981.     finally
  982.       EndReport(hReport);
  983.     end;
  984.   finally
  985.     StrDispose(MyFile_);
  986.     StrDispose(MyApp_);
  987.     StrDispose(MyLib_);
  988.     StrDispose(MyRep_);
  989.   end;
  990. end;
  991.  
  992. { ************************************************************************** }
  993. function TRRX65.LoadFromFile(MyFile:String):boolean;
  994. { ************************************************************************** }
  995. var
  996.   hReport:Integer;
  997.   MyFile_,MyApp_,MyLib_,MyRep_:PChar;
  998. begin
  999.   MyFile_:=StrAlloc(256);
  1000.   MyApp_:=StrAlloc(256);
  1001.   MyLib_:=StrAlloc(256);
  1002.   MyRep_:=StrAlloc(256);
  1003.   try
  1004.     Result:=false;
  1005.     StrPCopy(MyApp_,fAppName);
  1006.     StrPCopy(MyLib_,fLibName);
  1007.     StrPCopy(MyRep_,fRepName);
  1008.  
  1009.     StrPCopy(MyFile_,MyFile);
  1010.     hReport:=getRunTimeRecord(MyApp_,MyFile_);
  1011.     if hReport>0 then
  1012.     begin
  1013.       try
  1014.         { Load report information into this object }
  1015.         Result:=true;
  1016.         loadfromreporth(hReport);
  1017.       finally
  1018.         EndReport(hReport);
  1019.       end;
  1020.     end;
  1021.   finally
  1022.     StrDispose(MyFile_);
  1023.     StrDispose(MyApp_);
  1024.     StrDispose(MyLib_);
  1025.     StrDispose(MyRep_);
  1026.   end;
  1027. end;
  1028.  
  1029. { ************************************************************************** }
  1030. procedure TRRX65.SetRelationTables(Value:Tstrings);
  1031. { ************************************************************************** }
  1032. begin
  1033.   fRelationTables.Assign(Value);
  1034. end;
  1035.  
  1036. { ************************************************************************** }
  1037. procedure TRRX65.SetRelationIndexs(Value:Tstrings);
  1038. { ************************************************************************** }
  1039. begin
  1040.   fRelationIndexs.Assign(Value);
  1041. end;
  1042.  
  1043. { ************************************************************************** }
  1044. procedure TRRX65.SetRelationTags(Value:Tstrings);
  1045. { ************************************************************************** }
  1046. begin
  1047.   fRelationTags.Assign(Value);
  1048. end;
  1049.  
  1050. { ************************************************************************** }
  1051. procedure TRRX65.SetRelationAlias(Value:Tstrings);
  1052. { ************************************************************************** }
  1053. begin
  1054.   fRelationAlias.Assign(Value);
  1055. end;
  1056.  
  1057. { ************************************************************************** }
  1058. procedure TRRX65.LoadRelations(hReport:Integer);
  1059. { ************************************************************************** }
  1060. var
  1061.   Table_,Index_,Tag_,Alias_:Pchar;
  1062. begin
  1063.   Table_:=StrAlloc(256);
  1064.   Index_:=StrAlloc(256);
  1065.   Tag_:=StrAlloc(256);
  1066.   Alias_:=StrAlloc(256);
  1067.   try
  1068.  
  1069.     if GetFirstRelationInfo(hReport,Table_,StrBufSize(Table_),Index_,StrBufSize(Index_),
  1070.                           Tag_,StrBufSize(Tag_),Alias_,StrBufSize(Alias_)) then begin
  1071.  
  1072.       fRelationTables.Add(StrPas(Table_));
  1073.       fRelationIndexs.Add(StrPas(Index_));
  1074.       fRelationTags.Add(StrPas(Tag_));
  1075.       fRelationAlias.Add(StrPas(Alias_));
  1076.     end;
  1077.     while GetNextRelationInfo(hReport,Table_,StrBufSize(Table_),Index_,StrBufSize(Index_),
  1078.                             Tag_,StrBufSize(Tag_),Alias_,StrBufSize(Alias_)) do begin
  1079.       fRelationTables.Add(StrPas(Table_));
  1080.       fRelationIndexs.Add(StrPas(Index_));
  1081.       fRelationTags.Add(StrPas(Tag_));
  1082.       fRelationAlias.Add(StrPas(Alias_));
  1083.     end;
  1084.   finally
  1085.     StrDispose(Table_);
  1086.     StrDispose(Index_);
  1087.     StrDispose(Tag_);
  1088.     StrDispose(Alias_);
  1089.   end;
  1090. end;
  1091.  
  1092.  
  1093. { ************************************************************************** }
  1094. procedure TRRX65.LoadScopes(hReport:Integer);
  1095. { ************************************************************************** }
  1096. var
  1097.   Scope:Pchar;
  1098. begin
  1099.   Scope:=StrAlloc(256);
  1100.   try
  1101.     if GetLowScope(hReport,Scope,StrBufSize(Scope)) then
  1102.       fScopeLow:=StrPas(Scope);
  1103.     if GetHighScope(hReport,Scope,StrBufSize(Scope)) then
  1104.       fScopeHigh:=StrPas(Scope);
  1105.   finally
  1106.     StrDispose(Scope);
  1107.   end;
  1108. end;
  1109.  
  1110. { ************************************************************************** }
  1111. procedure TRRX65.LoadIndex(hReport:Integer);
  1112. { ************************************************************************** }
  1113. var
  1114.   Index_,Type_,Tag_:Pchar;
  1115.   TypeString:String;
  1116. begin
  1117.   Index_:=StrAlloc(256);
  1118.   Type_:=StrAlloc(256);
  1119.   Tag_:=StrAlloc(256);
  1120.   try
  1121.  
  1122.     if GetMasterIndexInfo(hReport,Index_,StrBufSize(Index_),Type_,Tag_,
  1123.                           StrBufSize(Tag_)) then begin
  1124.       fMasterIndexName:=StrPas(Index_);
  1125.       fMasterIndexTag:=StrPas(Tag_);
  1126.  
  1127.       TypeString:=StrPas(Type_);
  1128.       if TypeString[1]='N' then
  1129.         MasterIndexType:=rrdtNumeric;
  1130.       if TypeString[1]='D' then
  1131.         MasterIndexType:=rrdtDate;
  1132.       if TypeString[1]='C' then
  1133.         MasterIndexType:=rrdtCharacter;
  1134.  
  1135.     end;
  1136.   finally
  1137.     StrDispose(Index_);
  1138.     StrDispose(Type_);
  1139.     StrDispose(Tag_);
  1140.   end;
  1141. end;
  1142.  
  1143.  
  1144. end.
  1145.